package com.xjoyt.pay.master.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

import com.xjoyt.pay.abstracts.AbstractLockAspect;
import com.xjoyt.pay.annotations.LockMethod;
import com.xjoyt.pay.master.PayMasterApp;

/**
 * 分布式锁切面
 * 
 * @author Administrator
 *
 */
@Component
@Aspect
public class LockAspect extends AbstractLockAspect {

	@Autowired
	private StringRedisTemplate stringRedisTemplate;

	@Override
	@Around("execution (com.xjoyt.pay.dto.ExecuteResult com.xjoyt.pay.master.services.*.*(..) ) && @annotation(annotation) ")
	public Object invoke(ProceedingJoinPoint point, LockMethod annotation) {
		return super.invoke(point, annotation);
	}

	@Override
	protected StringRedisTemplate getRedisTemplate() {
		StringRedisTemplate redisTemplate = PayMasterApp.getBean(StringRedisTemplate.class);
		if (redisTemplate == null)
			return stringRedisTemplate;
		return redisTemplate;
	}
}
